var app = getApp();
Page({
    data:{
        params : {},
        info : {},
        datalist : [],
        isrule : false,
        jifengoods : [],
        leftpos : 0,
        issignin : false,
        isshowprize : false,
        prize : {},
        log : [],
        allprize : [],
        goodslist : [],
        shoplist : [],
        isauth : false,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        
        var zfid = options.zfid ? options.zfid : '';
        var shopid = options.shopid ? options.shopid : '';
        self.data.options = options;

        app.com.auth(function(){
            
            app.com.http('daysign','POST',{op:'info',zfid:zfid},0,false,'','',function(res){
                if (!res.data.errno && res.data ) {
                    self.setData({
                        params : res.data.data.params,
                        isauth : res.data.data.isauth,
                        info : res.data.data.info,
                        jifengoods : res.data.data.jifengoods,
                        dayarr : res.data.data.dayarr,
                        log : res.data.data.log,
                        allprize : res.data.data.allprize,
                        goodslist : res.data.data.goodslist,
                        shoplist : res.data.data.shoplist,
                        shopid : shopid,
                        inited : true,
                    },function(){
                        if( res.data.data.isauto == 1 ){
                            self.signin();
                        }
                    });

                    wx.setNavigationBarTitle({
                        title:  '每日签到',
                    });

                }else{
                    app.com.alert(res.data.message,function(){
                        app.com.backPage(options.zfid);
                    });
                }
            });

        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
        });
        
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    back(){
        app.com.backPage();
    },
    showdetail(){
        this.setData({
            isrule : !this.data.isrule,
        })
    },
    signin(){
        var self = this;

        if( self.data.isauth ){
            this.loginauth = this.selectComponent('#loginauth');
            this.loginauth.hideauth();
            return false;
        }

        var postdata = {
            op : 'signtoday',
        }
        app.com.getLocation(self,function(loc){
            postdata.lng = loc.longitude;
            postdata.lat = loc.latitude;

            app.com.http('daysign','POST',postdata,0,true,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        issignin : true,
                        prize : res.data.data.prize,
                        ['dayarr.'+res.data.data.today+'.issign'] : 1,

                    });
                }else{
                    app.com.alert(res.data.message);
                }
            });

        })

    },
    showsignfn(){
        this.setData({
            issignin : !this.data.issignin,
            isshowprize : this.data.prize.choutimes > 0 || this.data.prize.list.length > 0 ? true : false,
        })
    },
    showprizefn(){
        this.setData({
            isshowprize : !this.data.isshowprize,
        })
    },
    authed(){
        this.setData({
            isauth : false,
        })
        this.signin();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})